package com.huan.config;

import com.alibaba.fastjson.JSON;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;

import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.stereotype.Component;

@Component
public class JsonMessageConverter implements MessageConverter {

  @Override
  public Message toMessage(Object object, MessageProperties props) {
    String json = com.alibaba.fastjson.JSON.toJSONString(object);
    return new Message(json.getBytes(), props);
  }

  @Override
  public Object fromMessage(Message message) {
    String json = new String(message.getBody());
    return com.alibaba.fastjson.JSON.parseObject(json);
  }

}

